package com.hongye.proprietary.service.impl;

import com.hongye.proprietary.entity.AgentUserEntity;
import com.hongye.proprietary.entity.CompanyHomeEntity;
import com.hongye.proprietary.service.AgentUserService;
import com.hongye.proprietary.service.CompanyHomeService;
import com.hongye.proprietary.service.UserHomeService;
import com.hongye.proprietary.vo.AgentCompanyVo;
import com.hongye.proprietary.vo.HomeSpaceVo;
import com.hongye.proprietary.vo.LeaderboardVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hongye.common.utils.PageUtils;
import com.hongye.common.utils.Query;

import com.hongye.proprietary.dao.SpaceHomeDao;
import com.hongye.proprietary.entity.SpaceHomeEntity;
import com.hongye.proprietary.service.SpaceHomeService;


@Service("spaceHomeService")
public class SpaceHomeServiceImpl extends ServiceImpl<SpaceHomeDao, SpaceHomeEntity> implements SpaceHomeService {

    @Autowired
    AgentUserService agentUserService;
    @Autowired
    CompanyHomeService companyHomeService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SpaceHomeEntity> page = this.page(
                new Query<SpaceHomeEntity>().getPage(params),
                new QueryWrapper<SpaceHomeEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<HomeSpaceVo> homecircle() {
        List<AgentCompanyVo> leaderboardlist = agentUserService.HomeCompany();
        ArrayList<HomeSpaceVo> homeSpaceVos = new ArrayList<>();

        //查询所有楼市圈内容。
        List<SpaceHomeEntity> spaceHomeEntities = this.baseMapper.selectList(null);
        for (SpaceHomeEntity spaceHomeEntity : spaceHomeEntities) {
            for (AgentCompanyVo leaderboardVo : leaderboardlist) {
                if (leaderboardVo.getAgentId().equals(spaceHomeEntity.getAgentId())){
                    HomeSpaceVo homeSpaceVo = new HomeSpaceVo();
                    BeanUtils.copyProperties(spaceHomeEntity,homeSpaceVo);
                    BeanUtils.copyProperties(leaderboardVo,homeSpaceVo);
                    homeSpaceVos.add(homeSpaceVo);
                }
            }




        }
        return homeSpaceVos;
    }

}